﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;


namespace gradeManager
{
    public partial class AddForm : Form
    {
        public string txt_stuid = null;
        public string txt_stuname = null;
        public AddForm(string id, string name)
        {
            InitializeComponent();
            txt_stuid = id;
            txt_stuname = name;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {

        }

       private void button1_Click(object sender, EventArgs e)
        {
            //SQLiteConnection con = new SQLiteConnection("Data Source=" + Application.StartupPath + @"\grade.db;");
            //con.Open();
            //string str = "insert into score_info(stuid,semester,numofcourse,nameofcourse,teacher,credit,grade,stuname) values (" + txt_stuid + ",'"
            //    + txt_semester.Text + "'," + txt_num.Text + ",'" + txt_name.Text + "','" +
            //     txt_teaher.Text + "'," + txt_credit.Value + "," + txt_grade.Text + ",'" + txt_stuname + "')";

            //SQLiteCommand cmd = new SQLiteCommand(str, con);
            //cmd.ExecuteNonQuery();
            //con.Close();
            //con.Dispose();


            LinkSqLiteDB db = new LinkSqLiteDB();   //创建数据库连接对象
            if (db.DBconn())

            { //连接数据库
                string str = "insert into score_info(stuid,semester,numofcourse,nameofcourse,teacher,credit,grade,stuname) values (" + txt_stuid + ",'"
                    + txt_semester.Text + "'," + txt_num.Text + ",'" + txt_name.Text + "','" +
                     txt_teaher.Text + "'," + txt_credit.Value + "," + txt_grade.Text + ",'" + txt_stuname + "')";
                string info = "添加成功！";

                if (db.UpdataDeletAdd(str))
                {
                    DialogResult dr = MessageBox.Show(info, "标题", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    if (dr == DialogResult.OK)
                    {
                        this.Visible = false;//隐藏当前窗口
                    }
                }
            }

            db.DBclose();//关闭数据连接
        }

        private void 添加_Load(object sender, EventArgs e)
        {
            MaximizeBox = false;        //关闭注册窗口的最大化功能
        }
    }
}

